//
//  CZTitleButton.m
//  OCKSFWeibo
//
//  Created by 盛 发 况 on 16/4/18.
//  Copyright © 2016年 盛 发 况. All rights reserved.
//

#import "CZTitleButton.h"

@implementation CZTitleButton

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self setImage:[UIImage imageNamed:@"navigationbar_filter_background_highlighted"] forState:UIControlStateHighlighted];
        
    }
    return self;
}

-(void)layoutSubviews {
    [super layoutSubviews];

    if (self.currentImage == nil) return;
    
    self.titleLabel.x = 0;
    self.imageView.x = CGRectGetMaxX(self.titleLabel.frame);

}
// 重写setTitle方法，扩展计算尺寸功能
- (void)setTitle:(NSString *)title forState:(UIControlState)state {

    [super setTitle:title forState:state];
    
    [self sizeToFit];
}

- (void)setImage:(UIImage *)image forState:(UIControlState)state {

    [super setImage:image forState:state];
    
    [self sizeToFit];

}

@end




